import { queryMatDetail, auditMat } from '../services/api';

export default {
  namespace: 'matdetail',

  state: {
    matinfo: {},
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      const response = yield call(queryMatDetail, payload);
      //console.log('log', response);
      yield put({
        type: 'save',
        payload: response.adMatDet,
      });
    },
    *auditMat({ payload, callback }, { call, put }) {
      const response = yield call(auditMat, payload);
      if (response?.result?.code === 2001) {
        message.error('提交出错，请检查');
      } else if (callback) callback();
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        matinfo: action.payload,
      };
    },
  },
};
